class Gizmo:
    def __init__(self):
        print('Gizmo id is %d' % id(self))


#
# x = Gizmo() * 12
# y = Gizmo() * 10

# charles = {'name': 'A', 'born': 1}
# lewis = charles
# print(lewis is charles)
# print(id(lewis))
# print(id(charles))
# alex = {'name': 'A', 'born': 1}
# print(charles == alex)
# print(alex is charles)

# t1 = (1, 2, [30, 40])
# t2 = (1, 2, [30, 40])
# print(t1 == t2)
# print(t1 is t2)
# print(id(t1[-1]))
# t1[-1].append(50)
# print(id(t1[-1]))
# print(t1 == t2)
# print(t1 is t2)

# l1 = [1, [2, 3], (4, 5)]
# l2 = list(l1)
# print(l2 == l1)
# print(l2 is l1)



# l1 = [3, [66, 55, 44], (7, 8, 9)]
# l2 = copy.deepcopy(l1)
# l1.append(100)
# l1[1].remove(55)
# print(l1)
# print(l2)
# l2[1] += [33, 22]
# l2[2] += (10, 11)
# print(l1)
# print(l2)
# import copy
#
# a = [1, 2]
# b = [a, 3]
# a.append(b)
# print(a)
# c = copy.deepcopy(a)
# print(c)
#
# class HauntedBug:
#     def __init__(self, passengers=[]):
#         self.passenger = passengers
#
#     def pick(self, name):
#         self.passenger.append(name)
#
#     def drop(self, name):
#         self.passenger.remove(name)
#
#
# bus1 = HauntedBug(['A', 'B'])
# print(bus1.passenger)
# bus1.pick('C')
# bus1.drop('A')
# print(bus1.passenger)
#
# bus2 = HauntedBug()
# bus2.pick('D')
# print(bus2.passenger)
#
# bus3 = HauntedBug()
# print(bus3.passenger)
# bus3.pick('E')
# print(bus3.passenger)
#
# print(bus2.passenger is bus3.passenger)
# print(bus1.passenger)
# print(bus1.passenger is bus2.passenger)

import weakref

# a_set = {0, 1}
# wref = weakref.ref(a_set)
# print(wref())
#
# a_set = {0, 1, 4}
# print(wref())
#
# print(wref() is None)
# print(wref() is None)
#
# stock = weakref.WeakValueDictionary()
#
# a = [(1), (2), (3), (4)]
# for o in a:
#     stock[str(o)] = str(o)
# print(sorted(stock.keys()))
# del a
# print(sorted(stock.keys()))
# del o
# print(sorted(stock.keys()))

from array import array
import math


class Vector2d:
    typecode = 'd'

    def __init__(self, x, y):
        self.x = float(x)
        self.y = float(y)

    def __iter__(self):
        return (i for i in (self.x, self.y))

    def __repr__(self):
        class_name = type(self).__name__
        return '{}({!r},{!r})'.format(class_name, *self)

    def __str__(self):
        return str(tuple(self))

    def __bytes__(self):
        return (bytes([ord(self.typecode)]) +
                bytes(array(self.typecode, self)))

    def __eq__(self, other):
        return tuple(self) == tuple(other)

    def __abs__(self):
        return math.hypot(self.x, self.y)

    def __bool__(self):
        return bool(abs(self))


v1 = Vector2d(1, 2)
for i in v1:
    print(i)
